package com.fyt.controller;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.fyt.result.R;
import com.fyt.service.DiscoveryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RefreshScope
public class NacosDemoController {

//    @Value("${pattern.dateformat}")
//    private String date;

    private final RestTemplate restTemplate;

    @Autowired
    public NacosDemoController(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @Autowired
    private DiscoveryService discoveryService;

    @RequestMapping("/discover")
    public R discoverByOpenApi() {
        return discoveryService.registerNacosInstance();
    }

    @RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
    public String echo(@PathVariable String str) {
        return restTemplate.getForObject("http://service-provider/echo/" + str, String.class);
    }

//    @RequestMapping("/date")
//    public String de() {
//        return LocalDateTime.now().format(DateTimeFormatter.ofPattern(date));
//    }

}
